//
// Created by twlin on 2024/8/6.
//

#ifndef COMMUNICATION_CSOCKET_H
#define COMMUNICATION_CSOCKET_H

#include <iostream>
#include <unistd.h>

#define INVALID_SOCKET -1


typedef int socket_t;

class CSocket
{
public:
    static socket_t create(int family, int type, int protocol);
    static bool bind(socket_t so, struct sockaddr *addr, socklen_t len);
    static bool setsockopt(socket_t so, int level, int optname, const void *optval, socklen_t optlen);
    static bool listen(socket_t so, int listen = 5);
    static int accept(socket_t so, struct sockaddr * addr, socklen_t *addrlen);
    static bool connect(socket_t so, struct sockaddr *addr, socklen_t addrlen);
    static ssize_t send (socket_t fd, const void *buf, size_t n, int flags);
    static ssize_t recv (socket_t fd, void *buf, size_t n, int flags);
    static int close (socket_t fd);

    static int error();
};


#endif //COMMUNICATION_CSOCKET_H
